#!/usr/bin/python3
# -*- coding: utf-8 -*-
import EventLog as log
import time,sys
import prettytable as pt
import D_DQ4 as D
import numpy as np
import math

import tkinter as tk 

import matplotlib.pyplot as plt

defauleJDD = {11: 0, 12: 0, 13: 0, 14: 10, 15: 10, 16: 0
              , 21: 0, 22: 0, 23: 0, 24: 10, 25: 10, 26: 0
              , 31: 10, 32: 5, 33: 0, 34: 50, 35: 0, 36: 0, 37: 0
              , 41: 10, 42: 5, 43: 0, 44: 50, 45: 0, 46: 0, 47: 0
              , 71: 0, 72: 0}


def print_table(data,tabname = "Table"):
    root = tk.Tk()
    # root.title(tabname)
    
    label = tk.Label(root, text=tabname) 
    label.grid(row=0, column=0, columnspan=len(data[0]))
  
    rows = len(data)
    columns = len(data[0])
  
    for i in range(rows):
        for j in range(columns):
            e = tk.Entry(root) 
            e.config(width=10)
            e.grid(row=i+1, column=j)
            e.insert(0, data[i][j])
        
    root.mainloop()
  

class Tools():
    def __init__(self) -> None:
        self.LinkDQ40 = D.LinkDQ40()
        self.JointIDList = defauleJDD.keys()
    
    def posedata(self):
        posedata = []
        Joints = [[31,32,33,34,35,36,37],
                    [41,42,43,44,45,46,47],
                    [71,11,12,13,14,15,16],
                    [72,21,22,23,24,25,26]]
        posedata.append(['==================','==================','=================='
                             ,'==================','==================','=================='
                             ,'=================='])
        for aJoints in Joints:
            ret,rlt = self.LinkDQ40.GetJointData(aJoints)
            posedata.append(aJoints)
            posedata.append(ret)
            posedata.append(rlt)
            posedata.append(['==================','==================','=================='
                             ,'==================','==================','=================='
                             ,'=================='])
       
        
        return posedata
    
    def set_init(self):
        defauleJDD = {11: 0, 12: 0, 13: 20, 14: 40, 15: 20, 16: 0
              , 21: 0, 22: 0, 23: 20, 24: 40, 25: 20, 26: 0
              , 31: 0, 32: 10, 33: 0, 34: 00, 35: 0, 36: 0, 37: 0
              , 41: 0, 42: 10, 43: 0, 44: 00, 45: 0, 46: 0, 47: 0
              , 71: 0, 72: 0}
        JointNameList = list(defauleJDD.keys())
        JointNameData = list(defauleJDD.values())
        print(JointNameList,JointNameData)
        self.LinkDQ40.SetJointData(JointNameList,JointNameData)
        
if __name__ == "__main__":
    
    
    T = Tools()
    
    T.set_init()
    
    time.sleep(2)
    showdata = T.posedata()
    
    print_table(showdata,'机器人个关节关节角度展示')
    
    
    
    
    